package com.lzw.mall.admin.interceptor;


import com.lzw.mall.admin.entity.User;
import com.lzw.mall.admin.util.RequestUtil;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {


    //请求进入controller之前执行index.jsp
    //如果返回 true 表示可以进后边的拦截器或者controller
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user= RequestUtil.getCurrent();

        //System.out.println(user);
        if (user == null) {
            response.sendRedirect("/login");
        }
        return user!=null;
    }

}
